#计时功能版本2，采用高阶函数（本例中：函数作为作为另一函数的形参）方式实现
#功能：运行某个函数，如：print_odd()或wait_while()，并记录函数运行的时间
import time

def print_odd(n):
    for i in range(n):
        if i%2==0:
            print(i,end=",")
    print("\n print_odd is over...")

def wait_while(n1,n2,n3):
    time.sleep(n1+n2+n3)
    print("\nwait_while is over...")

#count_time的形参func是一个函数
def count_time(func,*args,**kwargs):
    start=time.time()
    func(*args,**kwargs)
    end=time.time()
    print("it takes {}s".format(end-start))

#函数print_odd作为函数count_time的实参
count_time(print_odd,2000)

#函数wait_while作为函数count_time的实参
count_time(wait_while,0.5,0.4,0.2)